/**
 * Created by Administrator on 15-8-18.
 */
$('#productManager').addClass('active');
$('#addProduct').addClass('active');
$('#xy_product').addClass('active');
function addLilv(type){
    if(type==1){
        $("#lilvs_1").show();
        $("#lilvs_2").hide();
        $("#lilvs_3").hide();
    }
    if(type==2){
        $("#lilvs_1").hide();
        $("#lilvs_2").show();
        $("#lilvs_3").hide();
    }
    if(type==3){
        $("#nianLilv").empty();
        var obj=  $("input[name='terms']:checked");
        obj.each(function(a,b){
            $("#nianLilv").append("<p>"+$(b).val()+"个月:  <input type='text' name='rate3[]'  class='m-wrap span3'>%</p>");
        });
        $("#lilvs_1").hide();
        $("#lilvs_2").hide();
        $("#lilvs_3").show();
    }
}
function newlilv3(){
        $("#nianLilv").empty();
            var obj=  $("input[name='terms']:checked");
            obj.each(function(a,b){
                    if(a%3==2){
                        $("#nianLilv").append("<span>"+$(b).val()+"个月:  <input type='text' name='rate3[]'  class='m-wrap span2'>%</span><br/><span class='span1'></span>");
                    }else{
                        $("#nianLilv").append("<span>&nbsp;"+$(b).val()+"个月:  <input type='text' name='rate3[]'  class='m-wrap span2'>%</span>");
                    }
             });
}
function addJinRate(){
        var min=$("#amount_min").val();
        var max=$("#amount_max").val();
        var obj=  $("input[name=max_amount]");
        obj.each(function(a,b){
         if($(b).val()==max){
             $(b).val('');
         }
     });
        $("#addJinRate").append("<p name='pAmount' ><span class='span1'></span>&nbsp;&nbsp;&nbsp;&nbsp;<input type='text'   name='min_amount[]' class='m-wrap span2'> ——<input type='text'   name='max_amount[]' class='m-wrap span2' value='"+max+"'> 万 &nbsp;&nbsp;&nbsp; " + "<input type='text' name='rate2[]' class='m-wrap span2' > %</p>");
}
function delJinRate(){
    var max=$("#amount_max").val();
    var obj=  $("p[name=pAmount]");
    obj.each(function(a,b){
        if(a==obj.length-1){
            $(b).remove();
        }
    });
    var am=  $("input[name=max_amount]");
    am.each(function(a,b){
        if(a==am.length-1){
            $(b).val(max);
        }
    });
}
function zh_bank(id,url,type){
    $("#"+type).empty();
    $.ajax({
        type:"POST",
        dataType:"json",
        data:{'id':id},
        url:url,
        success:function(data) {
            var obj=eval(data);
            $.each(obj,function(k,v){
                $("#"+type).append("<option value='"+ v.id+"'>"+ v.name+"</option>");
            });
        }
    });
}
function searchHouse(name,url){
    if(name==""){
        return false;
    }
    $("#addHouse").empty();
    $.ajax({
        type:"POST",
        dataType:"json",
        data:{'name':name},
        url:url,
        success:function(data) {
            var obj=eval(data);
            $.each(obj,function(k,v){
                $("#addHouse").append("<li id=\"addli_"+v.id+"\" onclick=\"tianjia( '"+ v.id+"' ,'"+v.name+"','"+ v.thumb_pic+"')\"><img style=\"width: 40px;height: 40px\" src=\""+v.thumb_pic+"\">&nbsp;&nbsp;&nbsp;"+ v.name+"</li> ");
            });
        }
    })
}
function tianjia(id,name,src){
    var count=  $("#newHouse li").length;
    if(count==10){
        alert("最多添加10个合作楼盘");
        return false;
    }
    $("#addli_"+id).remove();
    $("#newHouse").prepend("<li onclick='javascript:$(this).remove();'><input type='hidden' name='house_id[]'  value='"+id+"'><img style='width: 40px;height: 40px' src='"+ src+"' />&nbsp;&nbsp;&nbsp;"+ name+"</li> ");
}